package com.mmall.concurrency.threads;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 方式三：实现Callable接口
 */
public class ThreadCallableTest implements Callable<String> {//步骤 1
    @Override
    public String call() { //步骤 2
        //call 方法的返回值类型是 String
        //call 方法是线程具体逻辑的实现方法
        return "create thread by implements Callable";
    }
    public static void main(String[] args) throws ExecutionException, InterruptedException{
        FutureTask<String> future1 = new FutureTask<String>(new ThreadCallableTest());
        Thread thread1 = new Thread(future1);
        thread1. start();
        System.out.println(future1.get());

        //匿名内部类创建 Thread
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("通过匿名内部类创建Thread");
            }
        });
        t.start();

    }
}
